<!--
 * @Author: krsea 965837746@qq.com
 * @Date: 2025-03-04 09:33:52
 * @LastEditors: krsea 965837746@qq.com
 * @LastEditTime: 2025-03-04 09:44:31
 * @FilePath: \vue3-code\2306\week3\2.props的像素宽度.html
 * @Description: 
 * 
 * Copyright (c) 2025 by ${git_name_email}, All Rights Reserved. 
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>props传值 像素宽度</title>
    <!-- 引入vue.js -->
    <script src="../js/vue.js"></script>
</head>

<body>
    <!-- 挂载点 -->
    <div id="app">
        <my-component-name :width="width"></my-component-name>
        <!-- 输入框 bind v-model="width" vue 双向绑定 -->
        <input type="text" v-model="width"> 
    </div>
    <!-- <div v-bind:style="style" style="background-color: yellow;">组件内容宽度100px,背景颜色为黄色。</div> -->
    <!-- 使用javascript 脚本 -->
    <script type="text/javascript">
        Vue.component('my-component-name', {
            // ... options ...
            props:['width'],
            template: '<div v-bind:style="style" style="background-color: yellow;">\
                组件内容宽度100px,背景颜色为黄色。</div>',
            computed: {
                style: function () {
                    return {
                        width: this.width + 'px'
                    }
                }
            }
        });
        //vue 实例
        var app = new Vue({
            el: '#app',
            data: {
                  width: 120  
            }
        });

    </script>
</body>

</html>